<%--
  Created by IntelliJ IDEA.
  User: 20064
  Date: 2020/2/12
  Time: 16:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户注册</title>
    <!-- 字体 -->
    <link href="https://fonts.font.im/css?family=Ruslan+Display" rel="stylesheet">

    <!-- 图标 -->
    <link rel="icon" type="image/png" sizes="144x144" href="../images/airplane.png"/>
    <link rel="apple-touch-icon" type="image/png" sizes="144x144" href="../images/airplane.png"/>
    <link href="../js/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">

    <!-- 其他 -->
    <link rel="stylesheet" href="../js/bootstrap-4.4.1-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../css/userStyle.css">

    <style type="text/css">
        body {
            background-image: url("../images/plane2.jpg");
        }
    </style>


</head>
<body>
<div class="container">
    <div class="row">&nbsp;</div>
    <div class="row">
        <div class="header">
            <p>有的事情现在不做，就一辈子也不会做了。</p>
            <p>If you do n’t do something right now, you wo n’t do it for a lifetime.</p>
        </div>
    </div>
    <div class="row">&nbsp;</div>
    <div class="row my-row">
        <div class="myForm rounded m-auto rounded">
            <form action="userRegister.do" method="post">
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text"><i class="fa fa-user fa-fw"></i></span>
                    </div>
                    <input type="text" class="form-control" placeholder="请输入账号" required="required" name="userAccount">
                </div>
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text"><i class="fa fa-address-book fa-fw"></i></span>
                    </div>
                    <input type="text" class="form-control" placeholder="请输入手机号" required="required" name="userPhone">
                </div>
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text"><i class="fa fa-key fa-fw"></i></span>
                    </div>
                    <input type="password" class="form-control" placeholder="请输入密码" required="required" name="userPwd">
                </div>
                <div class="input-group mb-3">
                    <div class="input-group-prepend">
                        <span class="input-group-text"><i class="fa fa-key fa-fw"></i></span>
                    </div>
                    <input type="password" class="form-control" placeholder="请确认密码" required="required"
                           name="confirmPwd">
                </div>
                <div class="fn text-right">
                    <a href="./userLogin.jsp">去登陆</a>
                </div>
                <div class="my-button">
                    <button class="btn btn-info" type="submit">注册</button>
                </div>
            </form>
        </div>
    </div>
</div>


</body>
<script type="text/javascript" src="../js/jquery-3.4.1/jquery-3.4.1.js"></script>
<script type="text/javascript" src="../js/bootstrap-4.4.1-dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
    // function register() {
    //     var check = checkUserRegister();
    //     if (check) {
    //         var pwd1 = $("input[name='userPwd']").val();
    //         var pwd2 = $("input[name='confirmPwd']").val();
    //         if (pwd1 === pwd2) {
    //             $("form").submit();
    //         } else {
    //             alert("密码不一致！");
    //         }
    //     }
    // }

    $("form").submit(function () {
        var check = checkUserRegister();
        if (check) {
            var phone = $("input[name='userPhone']").val();
            if (!(/^1\d{10}$/.test(phone))) {
                alert("请输入正确的手机号！");
                return false;
            }
            var pwd1 = $("input[name='userPwd']").val();
            var pwd2 = $("input[name='confirmPwd']").val();
            if (pwd1 === pwd2) {
                return true;
            } else {
                alert("密码不一致！");
            }
        }
        return false;
    });

    function checkUserRegister() {
        var check = false;
        $.ajax({
            async: false,
            url: "checkUserRegister.do",
            type: "post",
            data: {userAccount: $("input[name='userAccount']").val(), userPhone: $("input[name='userPhone']").val()},
            dataType: "json",
            success: function (result) {
                check = result.check;
                if (check === false) {
                    alert(result.msg);
                }
            }
        });
        return check;
    }
</script>
</html>
